package com.hwl.demo1.service.impl;

import com.hwl.demo1.service.CashSuper;

/**
 * 返利收费
 * 例：满300返50
 *
 * @author sentry
 * @since 2023-02-25
 */
public class CashReturn extends CashSuper {

    /**
     * 返利条件
     */
    private final double moneyCondition;

    /**
     * 返利值
     */
    private final double moneyReturn;

    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double price, int num) {
        double result = price * num;
        if (moneyCondition > 0 && moneyReturn > 0 && result >= moneyReturn) {
            result = result - Math.floor(result / moneyCondition) * moneyReturn;
        }
        return result;
    }
}
